﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Futaba.SBus.Channels
{
	/// <summary>
	/// Generates <see cref="Channel">channels</see>
	/// </summary>
	public class ChannelFactory
	{

		#region Singleton

		private static ChannelFactory _singletonChannelFactory;
		private static readonly object ChannelFactorySingletonLock = new object();

		/// <summary>
		/// A singleton of this class
		/// </summary>
		public static ChannelFactory DefaultInstance
		{
			get
			{
				if (_singletonChannelFactory == null)
				{
					// ReSharper disable PossibleMultipleWriteAccessInDoubleCheckLocking
					lock (ChannelFactorySingletonLock)
					{
						if (_singletonChannelFactory == null)
							_singletonChannelFactory = new ChannelFactory();
					}
					// ReSharper restore PossibleMultipleWriteAccessInDoubleCheckLocking
				}
				return _singletonChannelFactory;
			}
		}

		#endregion

		/// <summary>
		/// Returns a general list of channels (16 + 2 Digi-Channels)
		/// </summary>
		public Channel[] GetDefaultChannels()
		{
			var list = new Channel[18];
			for (byte i = 1; i < 17; i++)
			{
				list[i - 1] = new Channel { DisplayName = string.Format("Channel-{0:00}", i), ChannelId = i };
			}
			for (byte i = 17; i < 19; i++)
			{
				list[i - 1] = new Channel { DisplayName = string.Format("DigiChannel-{0:0}", i), ChannelId = i };
			}
			return list;
		}

	}
}
